﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace FierceWar
{
	public struct Matrix3
	{
		public Matrix3(float f)
		{
			this.Elements = new float[3, 3];
		}

		public Matrix3(Matrix m)
		{
			this.Elements = new float[3, 3];

			this.Elements[0, 0] = m.M11;
			this.Elements[0, 1] = m.M12;
			this.Elements[0, 2] = m.M13;

			this.Elements[1, 0] = m.M21;
			this.Elements[1, 1] = m.M22;
			this.Elements[1, 2] = m.M23;

			this.Elements[2, 0] = m.M31;
			this.Elements[2, 1] = m.M32;
			this.Elements[2, 2] = m.M33;
		}

		public Matrix3(Matrix3 m)
		{
			this.Elements = new float[3, 3];

			this.Elements[0, 0] = m[0, 0];
			this.Elements[0, 1] = m[0, 1];
			this.Elements[0, 2] = m[0, 2];

			this.Elements[1, 0] = m[1, 0];
			this.Elements[1, 1] = m[1, 1];
			this.Elements[1, 2] = m[1, 2];

			this.Elements[2, 0] = m[2, 0];
			this.Elements[2, 1] = m[2, 1];
			this.Elements[2, 2] = m[2, 2];
		}

		public float this[int row, int column]
		{
			get
			{
				if (row > 2 || column > 2)
					throw new IndexOutOfRangeException();

				return this.Elements[row, column];
			}
			set
			{
				if (row > 2 || column > 2)
					throw new IndexOutOfRangeException();

				this.Elements[row, column] = value;
			}
		}


		public Vector3 Row(int row)
		{
			return new Vector3(this.Elements[row, 0],
							   this.Elements[row, 1],
							   this.Elements[row, 2]);
		}

		public Vector3 Column(int column)
		{
			return new Vector3(this.Elements[0, column],
							   this.Elements[1, column],
							   this.Elements[2, column]);
		}

		float[,] Elements;
	}
}
